package aliasMatching.model;

import java.util.ArrayList;
import java.util.List;
import javax.swing.event.TableModelEvent;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author amendrashrestha
 *
 * Here, we have defined the model of our table to display the results.
 */
public class MyTableModel extends AbstractTableModel {

    private String[] columns = new String[]{"Equality", "User 1", "User2 ID", "User 2", "Common", "Value"};
    List<DisplayInfo> all_rows;
    //List all_rows;

    public MyTableModel() {
        all_rows = new ArrayList<DisplayInfo>();
        //all_rows = new ArrayList();
    }

    @Override
    public int getColumnCount() {
        return columns.length;
    }

    @Override
    public int getRowCount() {
        return all_rows.size();
    }

    @Override
    public Object getValueAt(int arg0, int arg1) {

        if (arg0 >= 0 && arg0 < getRowCount() && arg1 >= 0 && arg1 < getColumnCount()) {
            switch (arg1) {
                case 0:
                    return all_rows.get(arg0).getDisplayType();
                case 1:
                    return all_rows.get(arg0).getUser1();
                case 2:
                    return all_rows.get(arg0).getUser2ID();
                case 3:
                    return all_rows.get(arg0).getUser2();
                case 4:
                    return all_rows.get(arg0).getCommon();
                case 5:
                    return all_rows.get(arg0).getValue();

            }
        }
        return null;
    }

    public void SetValue(DisplayInfo val) {
        all_rows.add(val);
        this.fireTableDataChanged();
    }

    public void resetTable() {
        all_rows.clear();
        this.fireTableDataChanged();
    }

    @Override
    public String getColumnName(int colno) {
        if (colno >= 0 && colno < getColumnCount()) {
            return columns[colno];
        }
        return null;
    }
}
